<%@page language="java" import="com.scalar.chiptrack.operations.LotView,
                                java.util.ArrayList,
                                java.util.Iterator,
                                com.scalar.chiptrack.commons.SessionKeys,
                                com.scalar.chiptrack.utils.ConfigManager,
                                com.scalar.chiptrack.commons.Constants"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/jsp/operations/split_merge_lots.jsp"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>

<SCRIPT language="JavaScript">
    var error = ""
	function openLot(lotId)
	{
		  	newWindow = window.open('<%=chipTracContext%>/lotTrace.do?lotId='+lotId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=570,height=420,resizable=no');
		  	newWindow.moveTo(130,140);
		  	newWindow.focus();
	}

	function submitPage(action)
    {
            var pa=document.getElementById("message");
            error = "";
            qty = document.splitLot.quantity1.value;
            if( qty == ""  )
            {
                error = "<li>  Please enter Quantity to be split"
                pa.innerHTML = error ;
            }
            if( !isInteger( qty ) || qty == "0"  )
            {
                error = "<li>  Quantity to be split should be positive integer"
                pa.innerHTML = error ;
            }
            if( error == "")
            {
                document.splitLot.lotaction.value = action;
	            document.splitLot.submit();
            }
    }

    function checkQuantity(name){
          var  x = eval(document.splitLot[name]);
          var pa=document.getElementById("message");
          error = "";
          pa.innerHTML = "";
          var qty  = document.splitLot.quantityIn.value;

          if( ( document.splitLot.quantityIn.value - x.value ) <= 0 )
          {
                error = "Quantity to be split should be less than Quantity In"
                x.value = "";
                document.splitLot.quantity0.value = qty;
                pa.innerHTML =  error;
                return false;
          }
          else
          {
                document.splitLot.quantity0.value = (document.splitLot.quantityIn.value - x.value)
                document.splitLot.splitQuantity.value = x.value;
                pa.innerHTML =  '&nbsp;';
                return true;
          }

    }
    function restrictCharacters(element)
    {
        if (event.keyCode < 47 || event.keyCode > 57 || ( element.value == '' && event.keyCode == 48 ) )
	    {
		    event.returnValue = false;
	    }
    }

</SCRIPT>

<!-- Top Header Start-->

<%@include file="/jsp/includes/header.jsp"  %>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@include file="/jsp/operations/operations_menu.jsp" %>

</TD>

<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="images/clear.gif" width=500 border=0>
<BR>


<!-- from here your body starts -->
<html:form name="splitLot"  type="com.scalar.chiptrack.ChipTrackActionForm" action="/splitLot.do">
<center><span class="NArialW">Split Lot</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>



<%
	String message = (String)request.getAttribute("errorMessage");
   	if(message==null)
   		message="";
%>
<%
 	if(!message.equals("")){
%>
<!--<p align ="center">
<strong><font face="Verdana" size="-5" align="center" color="#ff0000"><b><%=message%></b></font>
</p> -->
    <SCRIPT language="JavaScript1.2">
    	var pa=document.getElementById("message");
    	pa.innerHTML = "<%= message%>";
    </SCRIPT>
<%
 	}
 %>


<%
		LotView lview = (LotView)request.getAttribute("lview");
		String from = (String)request.getAttribute("from");
		session.setAttribute(SessionKeys.LOT_VIEW, lview);

                ArrayList splitList = (ArrayList)request.getAttribute("splitList");
                session.setAttribute(SessionKeys.SPLIT_LIST, splitList);

%>

<table border="0" width="90%" align=right>
<tr><td  colspan="3" align="left" class='NArialL'><FONT id="message" styleClass="NArialL" color='FF0000'>&nbsp;</FONT></TD></TR>
<% if ( !user.isActionAllowed ( Functionality.SPLIT_MERGE_LOTS, User.USER_ACTION_MODIFY  )  ) { %>
<tr><td colspan='3'>
<font class='NArialS' color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b>
</font></td></tr>
<% } %>
<tr><td colspan=3>

<%--<%@include file="/jsp/engineering/lot_info.jsp" %>--%>
  </td>
  </tr>
  <tr><td width="3%" colspan=6><img src="images/spacer.gif" height=10></td></tr>
    <tr><td colspan=6>
    	    	<table border="0" width="90%">
			<tr>
				<td width="15%"><font class="NArialL">Split Lot No</font></td>
				<td width="15%"><font class="NArialL">Quantity</font></td>
				<td width="10%">&nbsp;</td>
			</tr>
<%
         Iterator it = splitList.iterator();
         int i = 0;
         while(it.hasNext()){
         String name = "quantity"+(i++);
%>
	 	<tr>
			<td width="15%"><input type="text" name="T1" size="20" class="txfield" disabled=false value='<%= (String)it.next()%>'></td>
<%
                if("quantity0".equalsIgnoreCase(name)){
%>
			<td width="15%"><input type="text" name='<%= name%>' size="20" class="txfield" onKeyPress="javascript:restrictCharacters(this)" onkeyup="javascript:checkQuantity('<%= name%>')" disabled=false value='<%= lview.getQuantityIn() %>'></td>
<%
                }else{
%>
			<td width="15%"><input type="text" name='<%= name%>' size="20" class="txfield" onKeyPress="javascript:restrictCharacters(this)" onkeyup="javascript:checkQuantity('<%= name%>')"></td>
<%
                }
%>
			<td width="10%">&nbsp;</td>
		</tr>
<%
         }
%>
	 	</table>

    </td></tr>
	<tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
   <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
   </tr>
   <tr>
      <td colspan=5 align=center>
      <% String strFrom = "javascript:submitPage('"+from+"');"; %>

      <chiptrack:restrictedLink functionality='<%=Functionality.SPLIT_MERGE_LOTS%>' action='<%=User.USER_ACTION_MODIFY%>' href='<%=strFrom%>' onmouseover="window.status='Click to Save Splitting';return true" onmouseout="window.status='';return true">
        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" title="Click here to Save Splitting">
      </chiptrack:restrictedLink>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <%-- <img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif"></td> --%>
      <a href="javascript:document.splitLot.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif"  onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"  width="53" height="17"></a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:history.back();"><img border="0" width="39" height="17" src="<%=chipTracContext%>/jsp/includes/images/back.gif"  onmouseover="window.status='Click to go back';return true" onmouseout="window.status='';return true" title="Click here to go back"  width="53" height="17"></a>
    </tr>
  </table>

<input type="hidden" name="lotaction" value="">
<input type="hidden" name="quantityIn" value="<%= lview.getQuantityIn()%>">
<input type="hidden" name="splitQuantity" value="">

</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->

<%@include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</BODY>
</HTML>
